<?php
include_once "helpers/CFile.php";
include_once "helpers/Import.php";
include_once "helpers/Database.php";
include_once "helpers/Composer.php";
include_once "Misc.php";
include_once "Spreadsheet_Excel_Reader/Excel/reader.php";

$dbTech     = _DATABASE_TYPE_ORACLE;
$dbUserName = "NECS_APPL";
$dbUserPass = "ecsprj";
$dbSID      = "localhost/xe";

$Excel      = new Spreadsheet_Excel_Reader();
$Excel->setOutputEncoding('CP1251');

$srcFileField     = "C:\ConvertionFileField.txt";
$srcFileFieldType = "C:\ConvertionFileFieldType.txt";
$srcFileData      = "C:\ConvertionFileData.txt";
$srcXlsField      = "C:\ConvertionXlsField.xls";
$srcXlsFieldType  = "C:\ConvertionXlsFieldType.xls";
$srcXlsData       = "C:\ConvertionXlsData.xls";

$ErrHdl         = new Misc;
$ComposerQuery  = new Composer;
$ComposerQuery  = $ComposerQuery->init(_COMPOSER_TYPE_QUERY);

$ComposerQuery->initErrorHandler($ErrHdl);

$Db             = new Database;
$Db             = $Db->initTech($dbTech, $ErrHdl);

$Db->init($dbUserName,
          $dbUserPass,
          $dbSID,
          _NO_COMMENT);

if($Db->connect()){

  /**
   * init the Import
   */
  $Import     = new Import;

  $ImportDb   = $Import->init(_IMPORT_TO_DB, $ErrHdl);

  $File       = new CGFile;

  $File->initErrorHandler($ErrHdl);

  $ImportDb->init($Db,
                  _IMPORT_TYPE_FILE,
                  $ErrHdl,
                  $ComposerQuery,
                  $File,
                  $Excel);

  $ImportDb->readFileField($srcFileField,_DEFAULT_SEPARATOR_02);

  $ImportDb->readFileFieldType($srcFileFieldType,_DEFAULT_SEPARATOR_02);

  $ImportDb->import($Excel,
                    $srcFileData,
                    _DEFAULT_SEPARATOR_02);

  //$Db->commit();

  $Db->dc();
}else{

  $ErrHdl->usrDie(_DB_CONN_ERROR);
}
?>